package com.quectel.core.module.patrol.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.quectel.core.module.patrol.dao.VideoPatrolTaskSummaryDao;
import com.quectel.core.module.patrol.dto.VideoPatrolTaskSummaryDto;
import com.quectel.core.module.patrol.entity.VideoPatrolTaskSummaryEntity;
import com.quectel.core.module.patrol.service.VideoPatrolTaskSummaryService;
import com.quectel.util.common.CopyUtils;
import com.quectel.util.kit.Snowflake;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author caolu
 * @email louis.cao@quectel.com
 * @date 2020-07-07 15:48:10
 */
@DubboService
public class VideoPatrolTaskSummaryServiceImpl implements VideoPatrolTaskSummaryService {

    private static final Logger LOGGER = LoggerFactory.getLogger(VideoPatrolTaskSummaryServiceImpl.class);

    @Autowired
    private VideoPatrolTaskSummaryDao videoPatrolTaskSummaryDao;


    @Override
    public VideoPatrolTaskSummaryDto queryByTaskId(Long taskId) {
        VideoPatrolTaskSummaryEntity entity =
                videoPatrolTaskSummaryDao.selectOne(new QueryWrapper<VideoPatrolTaskSummaryEntity>().eq("task_id", taskId));
        return CopyUtils.copyObj(entity, VideoPatrolTaskSummaryDto.class);
    }

    @Override
    public List<VideoPatrolTaskSummaryDto> queryList(Map<String, Object> params) {
        List<VideoPatrolTaskSummaryEntity> list = videoPatrolTaskSummaryDao.queryList(params);
        return CopyUtils.copyList(list, VideoPatrolTaskSummaryDto.class);
    }

    @Override
    public int queryTotal(Map<String, Object> params) {
        return videoPatrolTaskSummaryDao.queryTotal(params);
    }

    @Override
    public Long save(VideoPatrolTaskSummaryDto dto) {
        VideoPatrolTaskSummaryEntity entity = CopyUtils.copyObj(dto, VideoPatrolTaskSummaryEntity.class);
        entity.setId(Snowflake.nextId());
        videoPatrolTaskSummaryDao.insert(entity);
        return entity.getId();
    }

    @Override
    public void updateById(VideoPatrolTaskSummaryDto dto) {
        VideoPatrolTaskSummaryEntity entity = CopyUtils.copyObj(dto, VideoPatrolTaskSummaryEntity.class);
        videoPatrolTaskSummaryDao.updateById(entity);
    }

    @Override
    public VideoPatrolTaskSummaryDto selectById(Long id) {
        VideoPatrolTaskSummaryEntity entity = videoPatrolTaskSummaryDao.selectById(id);
        return CopyUtils.copyObj(entity, VideoPatrolTaskSummaryDto.class);
    }

    @Override
    public void deleteById(Long id) {
        videoPatrolTaskSummaryDao.deleteById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteBatch(Long[] ids) {
        for (Long id : ids) {
            deleteById(id);
        }
    }
}
